<?php
	defined('BASEPATH') OR exit('No direct script access allowed');

	class Smail {
		public function __construct(){
			require('phpmail/PHPMailerAutoload.php');
			$this->mail = new PHPMailer(true);
			$this->init_config();
			// try { 
			// 		$mail = new PHPMailer(true); 
			// 		$mail->IsSMTP(); 
			// 		$mail->CharSet='UTF-8'; //设置邮件的字符编码，这很重要，不然中文乱码 
			// 		$mail->SMTPAuth = true; //开启认证 
			// 		$mail->Port = 25; 
			// 		$mail->Host = "smtp.sina.com"; 
			// 		$mail->Username = "senyuanzhijia@sina.com"; 
			// 		$mail->Password = "1988618a"; 
			// 		//$mail->IsSendmail(); //如果没有sendmail组件就注释掉，否则出现“Could not execute: /var/qmail/bin/sendmail ”的错误提示 
			// 		$mail->AddReplyTo("senyuanzhijia@sina.com","mckee");//回复地址 
			// 		$mail->From = "senyuanzhijia@sina.com"; 
			// 		$mail->FromName = "www.phpddt.com"; 
			// 		$to = "154063438@qq.com"; 
			// 		$mail->AddAddress($to); 
			// 		$mail->Subject = "phpmailer测试标题"; 
			// 		$mail->Body = "<h1>phpmail演示</h1>这是php点点通（<font color=red>www.phpddt.com</font>）对phpmailer的测试内容"; 
			// 		$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; //当邮件不支持html时备用显示，可以省略 
			// 		$mail->WordWrap = 80; // 设置每行字符串的长度 
			// 		//$mail->AddAttachment("f:/test.png"); //可以添加附件 
			// 		$mail->IsHTML(true); 
			// 		$mail->Send(); 
			// 		echo '邮件已发送'; 
			// 	} catch (phpmailerException $e) { 
			// 		echo "邮件发送失败：".$e->errorMessage(); 
			// 	} 
		}

		function init_config(){
			$this->mail->IsSMTP(); 
			$this->mail->CharSet='UTF-8'; //设置邮件的字符编码，这很重要，不然中文乱码 
			$this->mail->SMTPAuth = true; //开启认证 
			$this->mail->Port = 25; 
			$this->mail->Host = "smtp.sina.com"; 
			$this->mail->Username = "senyuanzhijia@sina.com"; 
			$this->mail->Password = "1988618a"; 
			$this->mail->AddReplyTo("senyuanzhijia@sina.com","senyuanzhijia");//回复地址 
			$this->mail->From = "senyuanzhijia@sina.com"; 
			$this->mail->FromName = "森源之家"; 
			$this->mail->WordWrap = 80; // 设置每行字符串的长度 
			$this->mail->IsHTML(true); 
		}

		function send($array){
			/*
				array(
					to => string or array,
					subject => string,
					body => string,
					addAttachment => string
				)
			*/
			if(is_array($array['to'])){
				for($i = 0; $i < count($array['to']); $i++){
					$this->mail->AddAddress($array['to'][$i]);
				}
			}elseif(is_string($array['to'])){
				$this->mail->AddAddress($array['to']);
			}
			$this->mail->Subject = $array['subject'];
			$this->mail->Body = $array['body'];
			if(isset($array['addAttachment'])){
				$this->mail->AddAttachment($array['addAttachment']); //可以添加附件 
			}
			try{
				$this->mail->send();
				return true;
			}catch (phpmailerException $e) { 
				echo "邮件发送失败：".$e->errorMessage();
				return false; 
			}
		}
	}